package com.shujia.day12;

import java.util.ArrayList;

public class Code03Demo {
    public static void main(String[] args) {

        UseAnimal<Cat> catUseAnimal = new UseAnimal<>();
        catUseAnimal.useFun(new Cat());

        UseAnimal<Dog> dogUseAnimal = new UseAnimal<>();
        dogUseAnimal.useFun(new Dog());

        System.out.println("=============");
        UseAnimal<Animal> useAnimal = new UseAnimal<>();
        useAnimal.useFun(new Animal());
        useAnimal.useFun(new Cat());
        useAnimal.useFun(new Dog());


        ArrayList<? super Animal> arrayList = new ArrayList<Animal>();
        ArrayList<? super Animal> arrayList2 = new ArrayList<Object>();

//        ArrayList<? super Animal> arrayList3 = new ArrayList<Cat>();  // Cat不是Animal的父类


    }
}

//class UseAnimalOther<? super A>{
//
//    public void useFun()
//}

class UseAnimal<T extends Animal> {

    public void useFun(T t) {
        t.run();
    }
}


class Animal {
    int age;

    public void run() {
        System.out.println("动物可以跑...");
    }
}

class Cat extends Animal {
    public void run() {
        System.out.println("猫可以上树..");
    }
}


class Dog extends Animal {
    public void run() {
        System.out.println("狗可以游泳..");
    }
}